package day326;

import common.TreeNode;

/**
 * @author tmh
 * @date 2023/3/26 19:10
 * @description
 */
public class T111二叉树的最小深度 {

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        if (root.left == null && root.right == null) {
            return 1;
        }
        int leftDepth = minDepth(root.left);
        int rightDepth = minDepth(root.right);
        if(root.left==null||root.right==null){
            return leftDepth+rightDepth+1;
        }
        return Math.min(leftDepth, rightDepth) + 1;

    }
}
